package cn.arikeky.rocket;

import cn.arikeky.order.domain.OrderPetAcquisition;
import cn.arikeky.order.mapper.OrderPetAcquisitionMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Slf4j
@Component
@RocketMQMessageListener(topic = "cancel_order",consumerGroup = "order_seek_master")
public class RocketMQConsumer implements RocketMQListener<String>{

    @Autowired
    private OrderPetAcquisitionMapper orderPetAcquisitionMapper;

    @Autowired
    private RocketMQTemplate rocketMQTemplate;


    @Override
    public void onMessage(String message) {
        System.out.println(message + "成功接收了");

        // 根据订单编号查询订单
        OrderPetAcquisition orderPetAcquisition = orderPetAcquisitionMapper.findBySn(message);
        // 跟据订单编号判断订单状态 未处理则设置订单状态为取消
        if (orderPetAcquisition.getState() == 0){
            orderPetAcquisition.setState(-1);
            orderPetAcquisitionMapper.update(orderPetAcquisition);
        }

    }
}
